package com.mp.chart.data;

import android.graphics.Color;

import java.util.ArrayList;
import java.util.List;


public class BollDataSet extends BarLineScatterCandleDataSet<BollEntry> {

    private float mBodySpace = 0.1f;


    private int mIncreasingColor = Color.argb(255, 222, 50, 109);
    private int mDecreasingColor = Color.argb(255, 58, 174, 98);
    private float mStrokeWidth = 1f;
    private float mCircleSize = 5f;

    public BollDataSet(List<BollEntry> yVals, String label) {
        super(yVals, label);
    }

    @Override
    public DataSet<BollEntry> copy() {
        List<BollEntry> yVals = new ArrayList<>();

        for (int i = 0; i < mYVals.size(); i++) {
            yVals.add((mYVals.get(i)).copy());
        }

        BollDataSet copied = new BollDataSet(yVals, getLabel());
        copied.mBodySpace = mBodySpace;
        copied.mHighLightColor = mHighLightColor;
        copied.mIncreasingColor = mIncreasingColor;
        copied.mDecreasingColor = mDecreasingColor;

        return copied;
    }

    public void setBodySpace(float space) {

        if (space < 0f)
            space = 0f;
        if (space > 0.45f)
            space = 0.45f;

        mBodySpace = space;
    }

    public float getBodySpace() {
        return mBodySpace;
    }

    @Override
    public void setColor(int color) {
        mIncreasingColor = color;
        mDecreasingColor = color;
    }

    public int getIncreasingColor() {
        return mIncreasingColor;
    }

    public void setIncreasingColor(int color) {
        this.mIncreasingColor = color;
    }

    public int getDecreasingColor() {
        return mDecreasingColor;
    }

    public void setDecreasingColor(int color) {
        this.mDecreasingColor = color;
    }

    public float getStrokeWidth() {
        return mStrokeWidth;
    }

    public void setStrokeWidth(float mStrokeWidth) {
        this.mStrokeWidth = mStrokeWidth;
    }

    public void setCircleSize(float size) {
        mCircleSize = size;
    }


    @Override
    protected void calcMinMax(int start, int end) {
        // super.calcMinMax();

        int size = mYVals.size();
        if (size == 0)
            return;

        List<BollEntry> entries = mYVals;

        int endValue;

        if (end == 0)
            endValue = size - 1;
        else
            endValue = end;

        mLastStart = start;
        mLastEnd = endValue;

        final BollEntry startEntry = mYVals.get(start);
        mYMin = startEntry.getLow();
        mYMax = startEntry.getHigh();
        int count = getValueCount();


//        System.out.println("endValue:" + endValue + ",size:" + size);
        for (int i = start + 1; i <= endValue && i < count; i++) {

            BollEntry e = entries.get(i);

            if (e.getLow() < mYMin)
                mYMin = e.getLow();

            if (e.getHigh() > mYMax)
                mYMax = e.getHigh();


        }
    }
}
